﻿using System;
using System.Linq;

namespace Diploma.Models
{
    public partial class Student : ISoftDeletable
    {
        public bool IsAssigned
        {
            get
            {
                if (CollaborationPropos != null && CollaborationPropos.DeletionDate == null &&
                    CollaborationPropos.IsApproved)
                    return true;
                return false;
            }
        }

        public CollaborationRoom CollaborationRoom
        {
            get
            {
                if (IsAssigned)
                    return CollaborationPropos.CollaborationRoom;

                return null;
            }
        }

        #region ISoftDeletable Members

        public void MarkForDeletion()
        {
            Mark(true);
        }

        public void UnmarkFromDeletion()
        {
            Mark(false);
        }

        #endregion

        protected void Mark(bool asDeleted)
        {
            if (CollaborationPropos != null)
                if (asDeleted) CollaborationPropos.MarkForDeletion();
                else CollaborationPropos.UnmarkFromDeletion();
            DeletionDate = asDeleted ? (DateTime?) DateTime.Now : null;
            Messages.ToList().ForEach(delegate(Message mes)
                                          {
                                              if (asDeleted) mes.MarkForDeletion();
                                              else mes.UnmarkFromDeletion();
                                          });
            PublicMessages.ToList().ForEach(delegate(PublicMessage pm)
                                                {
                                                    if (asDeleted) pm.MarkForDeletion();
                                                    else pm.UnmarkFromDeletion();
                                                });
            GlobalTasksCompletions.ToList().ForEach(delegate(GlobalTasksCompletion gtc)
                                                        {
                                                            if (asDeleted) gtc.MarkForDeletion();
                                                            else gtc.UnmarkFromDeletion();
                                                        });
        }
    }
}